package com.yulebaby.callsenter.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.bean.CallLogBean;
import com.yulebaby.callsenter.global.App;
import com.yulebaby.callsenter.utils.DateUtil;
import com.yulebaby.callsenter.utils.ImageLoader;

import java.util.List;

/**
 * Author: Zhangbo
 * Time: 2016/11/13
 * <p>
 * 通话记录的适配器
 */
public class CallLogAdapter extends BaseQuickAdapter<CallLogBean, BaseViewHolder> {

    public CallLogAdapter(List<CallLogBean> list) {
        super(R.layout.item_recycle_calllog, list);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, CallLogBean callLogBean) {
        baseViewHolder.setText(R.id.tv_phonenum, callLogBean.getCustomer_phone())
                .setText(R.id.tv_date, DateUtil.formatDateTimeDetail(callLogBean.getCall_time()))
                .setText(R.id.tv_calltime, DateUtil.timeChange(callLogBean.getCall_duration()).equals("0分0秒") ? "未接通" : DateUtil.timeChange(callLogBean.getCall_duration()))
                .setText(R.id.tv_phonename, callLogBean.getCustomer_name())
                .addOnClickListener(R.id.iv_play);

        switch (callLogBean.getPlayState()) {
            case 0:
//                ImageLoader.loadLocal(App.mContext, R.drawable.phone_fail, R.mipmap.ic_launcher, (ImageView) baseViewHolder.getView(R.id.iv_play));
                ImageLoader.load(App.mContext, R.drawable.phone_fail, (ImageView) baseViewHolder.getView(R.id.iv_play));
                break;
            case 1:
//                ImageLoader.loadLocal(App.mContext, R.drawable.phone_pause, R.mipmap.ic_launcher, (ImageView) baseViewHolder.getView(R.id.iv_play));
                ImageLoader.load(App.mContext, R.drawable.phone_pause, (ImageView) baseViewHolder.getView(R.id.iv_play));
                break;
            case 2:
                ImageLoader.load(App.mContext, R.drawable.phone_success, (ImageView) baseViewHolder.getView(R.id.iv_play));
//                Glide.with(mContext).load(R.drawable.phone_sucess).crossFade().placeholder(R.mipmap.ic_launcher).into((ImageView) baseViewHolder.getView(R.id.iv_play));
                break;
        }
        //通话类型，1 来电 .INCOMING_TYPE；2 已拨 .OUTGOING_；3 未接 .MISSED_
        switch (callLogBean.getCall_type()) {
            case 1:
                baseViewHolder.setText(R.id.tv_type, "呼入");
                break;
            case 2:
                baseViewHolder.setText(R.id.tv_type, "呼出");
                break;
            case 3:
                baseViewHolder.setText(R.id.tv_type, "未接通");
                break;
        }

    }
}
